const showFreeMemory = new function()
{
    var obj = null;
    var timerID = 0;
    var file = null;
    var istream = null;

    updateTimer = function() {
        if (timerID)
            clearTimeout(timerID);
        var res = 0;
        if (istream != null) {
            istream.init(file, 0x01, 0444, 0);
            istream.QueryInterface(Components.interfaces.nsILineInputStream);

            var line = {};
            /* skip MemTotal */
            istream.readLine(line);
            /* read MemFree */
            istream.readLine(line);
            res += Number(line.value.match(/\d+/));
            /* read Buffers */
            istream.readLine(line);
            res += Number(line.value.match(/\d+/));
            /* read Cached */
            istream.readLine(line);
            res += Number(line.value.match(/\d+/));
            res = Math.ceil(res/1024);
            istream.close();
        }
        document.getElementById("freememory_panel").label = res + "M";
        timerID = setTimeout("updateTimer()", 2000);
    };

    this.init = function() {
        //dump(navigator.platform);
        platform = "lin";
        file = Components.classes["@mozilla.org/file/local;1"]
            .createInstance(Components.interfaces.nsILocalFile);
        file.initWithPath("/proc");
        file.append("meminfo");
        istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
            .createInstance(Components.interfaces.nsIFileInputStream);
        updateTimer();
    };
}

window.addEventListener('load', function() {
        /* we expect to show it BEFORE any page is loaded */
        //gBrowser.addEventListener("load", showFreeMemory.init, true);
        showFreeMemory.init();
        },
        false);

